import React, { Component } from 'react'
import pubSub from "pubsub-js";

export default class Search extends Component {
    keyword = React.createRef()
    render() {
        return (
            <div>
                <section className="jumbotron">
                    <h3 className="jumbotron-heading">Search Github Users</h3>
                    <div>
                        <input ref={this.keyword} type="text" placeholder="enter the name you search" />
                        <button onClick={()=>{
                            const keyword = this.keyword.current.value.trim()
                            if(keyword.length>0) {
                                pubSub.publish('search', keyword)
                            } else {
                                alert('请输入搜索内容')
                            }
                        }}>Search</button>
                    </div>
                </section>
            </div>
        )
    }
}
